var jsondata=null;

//角色列表初始化
var grid=$("#roleTable").bootgrid({
	ajax: true,
    post: function ()
    {
        return jsondata;
    },
    url: "/platform/windows/role/showpage",
    css: {
        icon: 'zmdi icon',
        iconColumns: 'zmdi-view-module',
        iconDown: 'zmdi-expand-more',
        iconRefresh: 'zmdi-refresh',
        iconUp: 'zmdi-expand-less'
    },
    labels: {
        all: "全部",
        infos: "当前显示 {{ctx.start}} 到 {{ctx.end}} 条，共 {{ctx.total}} 条记录",
        loading: "数据加载中。",
        noResults: "对不起，查询不到任何相关数据",
        refresh: "刷新",
        search: "查询"
    },
    formatters: {
    	"enabled": function(column, row)
        {
    		if(row.enabled=="1")
    		{
    			return "已启动";
    		}
    		else
    		{
    			return "已禁用";
    		}
        },
        "commands": function(column, row)
        {
        	return "<button type=\"button\" class=\"btn btn-icon command-edit waves-effect waves-circle\" data-row-id=\"" + row.id + "\"><span class=\"zmdi zmdi-edit\"></span></button> " + 
            "<button type=\"button\" class=\"btn btn-icon command-delete waves-effect waves-circle\" data-row-id=\"" + row.id + "\"><span class=\"zmdi zmdi-delete\"></span></button>";
        }
    }
}).on("loaded.rs.jquery.bootgrid", function()
{
    grid.find(".command-edit").on("click", function(e)
    {	
    	getid($(this).data("row-id"));
    }).end().find(".command-delete").on("click", function(e)
    {
        alert("You pressed delete on row: " + $(this).data("row-id"));
    });
});

//创建首页
//$("#orgSources").append("<li id='indexOrg' class='active'> <a href='#'><i class='zmdi zmdi-home'></i> 组织机构</a></li>");

//根据点选的组织机构，重新加载用户列表
//var selectedWedgit=$('#indexOrg');
//selectedWedgit.attr("class","active");
//var url, id;
//function showUser(url, id) {
//    
//}

//组织机构树形块初始化
//$.ajax({
//    type: "POST",
//    url: "/platform/windows/org/showOrgTree",
//    dataType: "json",
//    async: false,
//    success: function (data) {
//
//        if (data.message == "ok") {
//            //获取经过权限验证后的菜单json
//            var json = data.orgs;
//            //对菜单树进行排列
//            //第一步：取出根节点下的菜单,形成一级菜单
//            var countRootOrg = 0;
//            for (var i = 0; i < json.length; i++) {
//                if (json[i]["parent_org"] == null) {
//                    $("#orgSources").append("<li id='first" + json[i]["id"] + "'> <a href='#'><i class='zmdi zmdi-menu'></i> <span>" + json[i]["name"] + "</span></a></li>");
//                    countRootMenu++;
//                }
//            }
//            //判断是否存在分配有二级菜单的一级菜单
//            if (countRootMenu > 0) {
//                for (var j = 0; j < json.length; j++) {
//                    if (json[j]["parent_org"] != null) {
//                        if ($("#first" + json[j]["parent_org"]).has("ul").length == 0) {
//                            $("#first" + json[j]["parent_org"]).attr("class", "sub-menu");
//                            $("#first" + json[j]["parent_org"]).append("<ul id='second" + json[j]["parent_org"] + "'></ul>");
//                        }
//                        $("#second" + json[j]["parent_org"]).append("<li id='" + json[j]["id"] + "'><a href='javascript:makeSelected(\"" + json[j]["url"] + "\"," + json[j]["id"] + ");'>" + json[j]["name"] + "</a></li>");
//                    }
//                }
//            }
//        }
//        else {
//
//        }
//    }
//});

//根据查询条件查询
//function queryRoleInfo()
//{
//	jsondata =
//	{
//		"s_roleid" : $('#s_roleid').val(),
//		"s_roledescription ": $('#s_roledescription').val(),
//		"s_roleName": $('#roleName').val()
//	};
//	var table = $('#roleTable').dataTable();
//	table.fnDraw();
//}

//跳转到编辑页面
function getid(){
	alert("a");
		 var formParam=$("#roleTable").serialize();
      $.ajax({     
             
          type: "POST",     
          //方法所在页面和方法名      
          url: "/platform/windows/role/findid",     
         
          data:formParam,
          async: false,
          dataType: "json",
         
          success: gotoEdit()
          
      });
      alert("b");
} 
function gotoEdit(id)
{
	role_editdemo_roleid=id;
	window.location.href = getWebRootPath()+"/windows/editdemo.html";
}


